﻿// <copyright file="TheColor.cs" company="BerlinSoft">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>Wernfried Schwenkner</author>
// <email>wernfried@schwenkner.de</email>
// <date>2009-10-21</date>
// <summary>
// Contains the TheColor class.
// </summary>

using System;
using System.Drawing;
using System.Xml.Serialization;

namespace SenseTimeTracker.Misc
{
	/// <summary>
	/// Class implements the color for serializing
	/// </summary>
	public class TheColor
	{
		/// <summary>
		/// Field contains the color
		/// </summary>
		private Color color = Color.Black;

		/// <summary>
		/// Initializes a new instance of the <see cref="TheColor"/> class.
		/// </summary>
		public TheColor()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="TheColor"/> class.
		/// </summary>
		/// <param name="color">Tho color to be initialized</param>
		public TheColor(Color color)
		{
			this.color = color;
		}

		/// <summary>
		/// Gets or sets the color
		/// </summary>
		[XmlIgnore]
		public Color Color
		{
			get
			{
				return color;
			}

			set
			{
				color = value;
				if (Persistance.Instance != null)
				{
					Persistance.Instance.Serialize();
				}
			}
		}

		/// <summary>
		/// Gets or sets the string of the color for serializing
		/// </summary>
		[XmlAttribute("Value")]
		public string SerializeColor
		{
			get { return "0x" + color.ToArgb().ToString("x06"); }
			set { color = Color.FromArgb(Convert.ToInt32(value, 16)); }
		}
	}
}
